package com.baizhi.cmfzdemo.service.impl;

import com.baizhi.cmfzdemo.dao.CmfzGuruDao;
import com.baizhi.cmfzdemo.entity.CmfzGuru;
import com.baizhi.cmfzdemo.service.CmfzGuruService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 54433 on 2019/4/7.
 */
@Service
public class CmfzGuruServiceImpl implements CmfzGuruService {
    //封装集合
    @Autowired
    private CmfzGuruDao cmfzGuruDao;
    public Map queryAllCmfzGuru(int page, int rows) {
        //获取总数数量
        Map map = new HashMap();
        int count = cmfzGuruDao.getCount();
        int page2 = (page - 1) * rows;
        try {
            List<CmfzGuru> cmfzGurus = cmfzGuruDao.queryAllCmfzGuru(page2, rows);
            //logger.info("查询上师");
            map.put("total", count);
            map.put("rows", cmfzGurus);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map deleteCmfzGuru(int[] ids) {
        Map map = new HashMap();
        try {
            cmfzGuruDao.deleteCmfzGuru(ids);
            //System.out.println("执行了删除操作**************");
            //logger.debug
            map.put("delete", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("delete", false);
        }
        return map;
    }

    @Override
    public Map addCmfzGuru(CmfzGuru cmfzGuru) {
        Map map = new HashMap();
        try {
            cmfzGuruDao.addCmfzGuru(cmfzGuru);
            map.put("add", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            map.put("add", false);
        }
        return map;
    }

    @Override
    public Map updateCmfzGuru(CmfzGuru cmfzGuru) {
        Map map = new HashMap();
        try {
            cmfzGuruDao.updateCmfzGuru(cmfzGuru);
            map.put("updateOk", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            map.put("updateOk", false);
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public List<CmfzGuru> queryAll() {
        return cmfzGuruDao.queryAll();
    }

    @Override
    public List<CmfzGuru> showAllGuru() {
        return cmfzGuruDao.showAllGuru();
    }
}
